FROM ccr.ccs.tencentyun.com/yy-dk/centos-sshd:7.0

MAINTAINER Yang <yangyufans@qq.com>

ENV HADOOP_VERSION hadoop-3.0.3

RUN yum install -y wget which

RUN cd / && wget http://yy-bak.oss-cn-qingdao.aliyuncs.com/jdk/jdk-8u172-linux-x64.tar.gz \
 && tar -zvxf jdk-8u172-linux-x64.tar.gz  -C /usr/local \
 && rm -rf jdk-8u172-linux-x64.tar.gz

ENV JDK_VERSION "jdk1.8.0_172"
ENV JAVA_HOME "/usr/local/$JDK_VERSION"

RUN cd / && wget https://downloads.apache.org/hadoop/common/$HADOOP_VERSION/$HADOOP_VERSION.tar.gz \
 && tar -zxvf $HADOOP_VERSION.tar.gz -C /usr/local \
 && rm -rf $HADOOP_VERSION.tar.gz

ENV HADOOP_HOME "/usr/local/$HADOOP_VERSION"
ENV PATH "$PATH:$JAVA_HOME/bin"
ENV PATH "$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin"

RUN echo "export JAVA_HOME=/usr/local/$JDK_VERSION" >> /etc/profile && \
    echo "export HADOOP_HOME=$HADOOP_HOME" >> /etc/profile && \
    echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile && \
    echo 'export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin' >> /etc/profile && \
    source /etc/profile

RUN mkdir /conf /logs /data

RUN echo "ZONE=Asia/Shanghai" > /etc/sysconfig/clock && \
    rm -rf /etc/localtime && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa && \
    cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

ENV YARN_LOG_DIR /logs

RUN sed -i 's/# export JAVA_HOME=/export JAVA_HOME=\/usr\/local\/jdk1.8.0_172/g' $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export HADOOP_LOG_DIR=/logs" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export HADOOP_PREFIX=$HADOOP_HOME" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export HDFS_NAMENODE_USER=root" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export HDFS_DATANODE_USER=root" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export HDFS_SECONDARYNAMENODE_USER=root" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export YARN_RESOURCEMANAGER_USER=root" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    echo "export YARN_NODEMANAGER_USER=root" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh && \
    sed -e "1 i\export YARN_LOG_DIR=\/logs" $HADOOP_HOME/etc/hadoop/yarn-env.sh > $HADOOP_HOME/etc/hadoop/yarn-env.sh.bak && \
    \mv $HADOOP_HOME/etc/hadoop/yarn-env.sh.bak $HADOOP_HOME/etc/hadoop/yarn-env.sh

COPY conf/* $HADOOP_HOME/etc/hadoop/

COPY start.sh /

RUN chmod 777 /start.sh

EXPOSE 22 8020 8088 8042 9870

CMD ["/start.sh"]
